package org.demo.jvm.threadpublic.method;

import lombok.extern.log4j.Log4j2;
import org.junit.Test;

/**
 * @Author:LiaoYouLe
 * @Date: Created in 2018/9/17
 * @Description 对string 在方法区还是在对象区域的判断
 * @Modifyied By:
 */
@Log4j2
public class StringCompare {
    static class PersonZ {
        public String name = "zhang";
    }

    static class PersonW {
        public String name = "zhang";

    }

    @Test
    public void compareDetail() {

        String name3 = new String("zhang");
        name3.intern();
        String name1 = "zhang";

        System.err.println(name3 == name1);

    }


    @Test
    public void compareIn() {
        PersonZ personZ = new PersonZ();

        PersonW personW = new PersonW();


        String zName = personZ.name;

        String wName = personW.name;

        System.err.println(zName == wName);

    }

}
